package com.atguigu.yygh.apartment.controller;

import com.atguigu.yygh.apartment.service.ApartmentInfoService;
import com.atguigu.yygh.apartment.service.ChamberService;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.hosp.ApartmentInfo;
import com.atguigu.yygh.vo.hosp.ApartmentInfoQueryVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLOutput;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/apartment/apartmentInfo")
//@CrossOrigin
public class ApartmentInfoController {
    @Autowired
    private ChamberService chamberService;

    @Autowired
    private ApartmentInfoService apartmentInfoService;

    //寝室学生列表
    @GetMapping("list/{page}/{limit}")
    public Result listChamber(@PathVariable Integer page,
                              @PathVariable Integer limit,
                              ApartmentInfoQueryVo apartmentInfoQueryVo) {
        Page<ApartmentInfo> pageMode = apartmentInfoService.selectApartmnetInfoPage(page,limit,apartmentInfoQueryVo);
        List<ApartmentInfo> content = pageMode.getContent();
        long totalElements = pageMode.getTotalElements();

        return Result.ok(pageMode);
    }

    //更新宿舍上线状态
    @ApiOperation(value = "更新宿舍上线状态")
    @GetMapping("updateApartmentInfoStatus/{id}/{status}")
    public Result updateApartmentInfoStatus(@PathVariable String id,
                                            @PathVariable Integer status){
        apartmentInfoService.updateStatus(id,status);
        return Result.ok();
    }

    //宿舍详情信息
    @ApiOperation(value = "宿舍详情")
    @GetMapping("showApartmentInfo/{id}")
    public Result showApartmentInfo(@PathVariable String id ){
        //ApartmentInfo apartmentInfo = apartmentInfoService.getApartmentInfoById(id);
        Map<String,Object> map = apartmentInfoService.getApartmentInfoById(id);
        return Result.ok(map);
    }

    //宿舍详情信息
    @ApiOperation(value = "宿舍详情")
    @GetMapping("getApartmentInfoByApartmentCode/{apartmentCode}")
    public Result getApartmentInfoByApartmentCode(@PathVariable String apartmentCode ){
        //ApartmentInfo apartmentInfo = apartmentInfoService.getApartmentInfoById(id);

        Map<String,Object> map= apartmentInfoService.findApartmentDeatil(apartmentCode);
        return Result.ok(map);
    }

}
